package com.ist.smartstation;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;

import com.ist.smartstation.dao.db.sqlite.PassengerSqliteDao;

public class PassengerListActivity extends ListActivity {

	private PassengerSqliteDao passengerDao;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.passenger_list);
		passengerDao = new PassengerSqliteDao(this);
		passengerDao.open();
		fillData();
		registerForContextMenu(getListView());
	}
	
	private void fillData() {
        Cursor notesCursor = passengerDao.fetchAllPassengers();
        startManagingCursor(notesCursor);
        String[] from = new String[]{passengerDao.KEY_ROWID, 
        		passengerDao.KEY_NAME,
        		passengerDao.KEY_NUM,
        		passengerDao.KEY_DEST};
        int[] to = new int[]{R.id.passenger_id,
        		R.id.passenger_name,
        		R.id.passenger_number,
        		R.id.passenger_destination};
        SimpleCursorAdapter notes = 
            new SimpleCursorAdapter(this, R.layout.passenger_row, notesCursor, from, to);
        setListAdapter(notes);
	}
}
